﻿Imports System.Xml.Serialization

Namespace Backup
    Public Class Job
        Public Id As Integer
        Public UniqueId As String
        Public Name As String
        Public Enabled As Boolean
        Public Comment As String

        Public LastRunUtc As Date
        Public NextRunUtc As Date

        Public Source As Source
        Public Destination As Destination
        Public Schedule As SchduleBase
        Public EncryptionProperties As EncryptionProperties
        Public CompressionProperties As CompressionProperties

        Public Versioning As Versioning
        Public Inertia As Inertia

        Public Actions As Actions
        Public Status As JobStatus = JobStatus.Idle
    End Class

    Public Enum JobStatus As Byte
        Idle = 0
        Running = 1
    End Enum

    Public Class Inertia
        Public Use As Boolean
        Public OverridenNextRun As Boolean
        Public CreatedOrDeletedTrigger As InertiaTrigger
        Public ChangedTrigger As InertiaTrigger
    End Class
    Public Class InertiaTrigger
        Public FileCount As Integer
        Public FilePercentageShare As Byte
    End Class

    Public Class Versioning
        Public KeepOldVersions As Boolean
        Public VersionsToKeep As Integer
        Public PurgeOldVersions As Boolean
        Public PurgeOldVersionsAfterDays As Integer
        Public KeepDeletedFilesOnly As Boolean
    End Class

    Public Class Source
        Public Folders As Generic.List(Of SourceFolder)
        Public Filter As FileFilter
    End Class
    Public Class SourceFolder
        <XmlText()> Public Path As String
        <XmlAttribute()> Public Recursive As Boolean = True
        Public CustomFilter As FileFilter
    End Class
    Public Class FileFilter
        Public IncludePatterns As Generic.List(Of MatchPattern)
        Public ExcludePatterns As Generic.List(Of MatchPattern)
        Public IncludeSystemFiles As Nullable(Of Boolean)
        Public IncludeHiddenFiles As Nullable(Of Boolean)
        Public ClearFileArchiveFlag As Nullable(Of Boolean)
    End Class
    Public Class Destination
        Public ContractIds As New Generic.List(Of Integer)
    End Class
    Public Enum DestinationMode
        Mirror
        Divide
    End Enum

    Public Class EncryptionProperties
        <XmlAttribute()> Public Type As EncryptionType
        Public Password As String
    End Class
    Public Enum EncryptionType As Byte
        None = 0
        Rijndael = 1
    End Enum
    Public Class CompressionProperties
        <XmlAttribute()> Public Type As CompressionType
        Public Level As CompressionLevel
    End Class
    Public Enum CompressionType As Byte
        None = 0
        LZMA = 1
    End Enum
    Public Enum CompressionLevel As Byte
        Store = 0
        Normal = 1
        Maximum = 2
        Ultra = 3
    End Enum
    <XmlInclude(GetType(RunOnChangeSchedule)), XmlInclude(GetType(HourlySchedule))> _
    <XmlInclude(GetType(DailySchedule)), XmlInclude(GetType(WeeklySchedule))> _
    <XmlInclude(GetType(MonthlySchedule))> _
    Public MustInherit Class SchduleBase
        Public Offset As TimeSpan
        Public RunIfMissed As Boolean
        Public MustOverride ReadOnly Property HasKnownNextRunTime() As Boolean
    End Class
    Public Class RunOnChangeSchedule
        Inherits SchduleBase
        Public Overrides ReadOnly Property HasKnownNextRunTime() As Boolean
            Get
                Return False
            End Get
        End Property
    End Class
    Public Class HourlySchedule
        Inherits SchduleBase
        Public Overrides ReadOnly Property HasKnownNextRunTime() As Boolean
            Get
                Return True
            End Get
        End Property
    End Class
    Public Class DailySchedule
        Inherits SchduleBase
        Public Overrides ReadOnly Property HasKnownNextRunTime() As Boolean
            Get
                Return True
            End Get
        End Property
    End Class
    Public Class WeeklySchedule
        Inherits SchduleBase
        Public Overrides ReadOnly Property HasKnownNextRunTime() As Boolean
            Get
                Return True
            End Get
        End Property
        Public DaysToRunOn(7 - 1) As Boolean
    End Class
    Public Class MonthlySchedule
        Inherits SchduleBase
        Public Overrides ReadOnly Property HasKnownNextRunTime() As Boolean
            Get
                Return True
            End Get
        End Property
        Public DaysToRunOn(31 - 1) As Boolean
    End Class

    Public Class Actions
        Public OnCompletion As CompletionAction
        Public OnError As ErrorAction
        Public OnFail As FailAction
    End Class
    Public Class CompletionAction
        Inherits EndActionBase
    End Class
    Public Class ErrorAction
        Inherits ActionBase
        Public RetryBeforeFailing As Boolean
        Public RetryCount As Short
        Public RetryDelayInSeconds As Integer
    End Class
    Public Class FailAction
        Inherits EndActionBase
    End Class
    Public MustInherit Class EndActionBase
        Inherits ActionBase
        Public DeactivateJob As Boolean
    End Class
    Public MustInherit Class ActionBase
        Public SendEmail As Boolean
        Public CustomEmail As Boolean
        Public CustomEmailAddress As String
        Public ShowTrayNotification As Boolean
    End Class
End Namespace